package question;

public class PrintOddTimesNum {
    public static void main(String[] args) {
        int[] nums1 = new int[] {1,1,1,1,2,2,3,3,3,4,4,4,4,5,5,6,6,6,6};
        int[] nums2 = new int[] {1,1,1,1,2,2,3,3,3,4,4,4,4,5,5,6,6,6};

        printOddTimesNum1(nums1);
        printOddTimesNum2(nums2);
    }

    private static void printOddTimesNum2(int[] nums) {
        int eor = 0;
        for(int i = 0; i < nums.length; i++) {
            eor ^= nums[i];
        }// 此时eor是a^b
        int onlyOne = 0;
        int rightOne = (~eor + 1) & eor;// 提取出最右边的1
        for(int i = 0; i < nums.length; i++) {
            if ((rightOne & nums[i]) == 1) {
                onlyOne ^= nums[i];
            }
        }
        System.out.println(onlyOne + " " + (onlyOne ^ eor));

    }

    private static void printOddTimesNum1(int[] nums) {
        int eor = 0;
        for(int i = 0; i < nums.length; i++) {
            eor ^= nums[i];
        }
        System.out.println(eor);
    }
}
